<?php
session_start();
include_once('./decode.php');
// error_reporting(E_ALL);
// ini_set('display_errors','on');
$jiemi = new jiemi();

if(!$_POST['studentId'] || !$_POST['password']){
	echo -1;
	exit;
}

function is_not_json($str){ 
	return is_null(json_decode($str));
}

$studentId = $_POST['studentId'];
$password = $_POST['password'];

if(!preg_match("/^\d{10}$/",$studentId)){
	echo -1;
	exit;
}

$url = 'http://61.183.207.40/zjdxgc/wbwj/get_pass.asp?studentId='.$studentId;
$data = file_get_contents($url);
if(!is_not_json($data)){
	$data = json_decode($data);
	$coded_pass = $data[0]->MM;
	$true_pass = $jiemi->Decode($coded_pass);
	if($password == $true_pass){
		$_SESSION['pass_check'] = $studentId;
		echo 1;
	}else{
		echo -2;
	}
}else{
	echo -3;
}